//
//  ZCSettingViewController.m
//  ZCBaiSi
//
//  Created by zc on 16/7/7.
//  Copyright © 2016年 zc. All rights reserved.
//

#import "ZCSettingViewController.h"
#import "ZCClearCacheCell.h"
@interface ZCSettingViewController ()

@end

@implementation ZCSettingViewController

static NSString *const ZCClearCacheCellId = @"ZCClearCacheCell";
static NSString *const ZCClearOtherCellId = @"OtherCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"设置";
    //[self getCacheSize];
    [self.tableView registerClass:[ZCClearCacheCell class] forCellReuseIdentifier:ZCClearCacheCellId];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ZCClearOtherCellId];
    // Do any additional setup after loading the view.
}

- (void)getCacheSize2{
    //总大小
    unsigned long long size = 0;
    //获取缓存文件夹路径
    NSString *cachesPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    NSString *dirpath = [cachesPath stringByAppendingPathComponent:@"default"];
    //文件管理者
    NSFileManager *mgr = [NSFileManager defaultManager];
    //获取文件夹的大小 == 获得文件夹中所有文件的总大小
    //[mgr contentsOfDirectoryAtPath:dirpath error:nil];
    //Enumerator :遍历器/迭代器
    NSDirectoryEnumerator *enumerator = [mgr enumeratorAtPath:dirpath];
    for (NSString *subpath in enumerator) {
        NSString *fullSubpath = [dirpath stringByAppendingPathComponent:subpath];
        //获得文件夹属性
        NSDictionary *atts = [mgr attributesOfItemAtPath:fullSubpath error:nil];
        //累加文件大小
        size += atts.fileSize;
    }
    ZCLog(@"%zd",size);
}

- (void)getCacheSize{
    //总大小
    unsigned long long size = 0;
    //获取缓存文件夹路径
   NSString *cachesPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    NSString *dirpath = [cachesPath stringByAppendingPathComponent:@"default"];
    //文件管理者
    NSFileManager *mgr = [NSFileManager defaultManager];
    //获取文件夹的大小 == 获得文件夹中所有文件的总大小
    //[mgr contentsOfDirectoryAtPath:dirpath error:nil];
   NSArray *subpaths = [mgr subpathsAtPath:dirpath];
    for (NSString *subpath in subpaths) {
        NSString *fullSubpath = [dirpath stringByAppendingPathComponent:subpath];
        //获得文件夹属性
        NSDictionary *atts = [mgr attributesOfItemAtPath:fullSubpath error:nil];
        //累加文件大小
        size += atts.fileSize;
    }
    ZCLog(@"%zd",size);
}

#pragma mark -- tableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        ZCClearCacheCell *cell = [tableView dequeueReusableCellWithIdentifier:ZCClearCacheCellId];
        return cell;
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ZCClearOtherCellId];
        if (indexPath.row == 1) {
            cell.textLabel.text = @"检查更新";
        }else if (indexPath.row == 2){
            cell.textLabel.text = @"给我们评分";
        }else{
            cell.textLabel.text = @"推送消息";
        }
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
